/*---------------------------
* Stata Version 15.1
* Code: 10/18/2019
* Title: 'Congressional Oversight Revisited: Politics and Procedure in Agency Rulemaking'
* Authors: Kenneth Lowande and Rachel Potter
* Summary: Replication code for producing all tables and figures. 
* Please report errors to: rapotter@virginia.edu
* ---------------------------
*/

*Note: users may need to install the "grc1leg" and "combomarginsplot" commands
*net install grc1leg, from(http://www.stata.com/users/vwiggins)
*ssc install combomarginsplot

use "rules-comments-7.dta"

* ---------------------------
* PRINT ARTICLE
* ---------------------------

**Figure 4: Effect of Staff Tenure on Marginal Increase in Probability of Commenting, by Ideological Quintile
mlogit type3  c.median_experience##i.distance_ord comm chair ranking senate est_avg_office_size if firm ==0 , base(1) robust cluster(id)

margins, at(median_experience = (0(1)7) distance_ord = (1)) predict(outcome(substantive)) noesample  saving(mts1, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (1)) predict(outcome(procedural)) noesample  saving(mtp1, replace) 
combomarginsplot  mts1 mtp1, name(mt1, replace) labels( "Substantive" "Procedural") graphregion(color(white)) title("Aligned") xtitle("") ytitle("Predicted Probability") ylab(,nogrid) xlab(none, ) legend(region(lcolor(white))) plot1opts(msymbol(O)) plot2opts(msymbol(D)) 

margins, at(median_experience = (0(1)7) distance_ord = (2)) predict(outcome(substantive)) noesample  saving(mts2, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (2)) predict(outcome(procedural)) noesample  saving(mtp2, replace) 
combomarginsplot  mts2 mtp2, name(mt2, replace) labels( "Substantive" "Procedural") graphregion(color(white)) legend(off) title("Nearly Aligned") xtitle("") ytitle("") ylab(none,nogrid) xlab(none, ) plot1opts(msymbol(O)) plot2opts(msymbol(D)) 

margins, at(median_experience = (0(1)7) distance_ord = (3)) predict(outcome(substantive)) noesample  saving(mts3, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (3)) predict(outcome(procedural)) noesample  saving(mtp3, replace) 
combomarginsplot  mts3 mtp3, name(mt3, replace) labels( "Substantive" "Procedural") graphregion(color(white)) legend(off) title("Slight Disagreement") xtitle("") ytitle("") ylab(none,nogrid) xlab(none, ) plot1opts(msymbol(O)) plot2opts(msymbol(D)) 
 
margins, at(median_experience = (0(1)7) distance_ord = (4)) predict(outcome(substantive)) noesample  saving(mts4, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (4)) predict(outcome(procedural)) noesample  saving(mtp4, replace) 
combomarginsplot  mts4 mtp4, name(mt4, replace) labels ("Substantive" "Procedural") graphregion(color(white)) legend(off) title("Moderate Disagreement") xtitle("Staff Tenure") ytitle("Predicted Probability") ylab(,nogrid)  plot1opts(msymbol(O)) plot2opts(msymbol(D)) 

margins, at(median_experience = (0(1)7) distance_ord = (5)) predict(outcome(substantive)) noesample  saving(mts5, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (5)) predict(outcome(procedural)) noesample  saving(mtp5, replace) 
combomarginsplot  mts5 mtp5, name(mt5, replace) labels("Substantive" "Procedural") graphregion(color(white)) legend(off) title("High Disagreement") xtitle("Staff Tenure") ytitle("") ylab(none,nogrid) plot1opts(msymbol(O)) plot2opts(msymbol(D)) 

grc1leg  mt1 mt2 mt3 mt4 mt5, ycommon row(2) col(3) graphregion(color(white)) name(complements, replace) 


* ---------------------------
* SUPPLEMENTARY INFORMATION
* ---------------------------
**Table SI-8: Robustness Checks Incorporating Preference and Proposal Uncertainty, 2007-2017

*Weighted first stage only
logit procedural comm chair ranking senate firm distcontw i.cong i.rule, robust cluster(id)
margins, dydx(comm chair ranking senate firm distcontw)

logit substantive comm chair ranking senate firm distcontw i.cong i.rule, robust cluster(id)
margins, dydx(comm chair ranking senate firm distcontw)

*Weighted first & 2nd stage (#givers)
logit procedural comm chair ranking senate firm distcontw i.cong i.rule [pweight = loggivers], robust cluster(id)
margins, dydx(comm chair ranking senate firm distcontw)

logit substantive comm chair ranking senate firm distcontw i.cong i.rule [pweight = loggivers], robust cluster(id)
margins, dydx(comm chair ranking senate firm distcontw)

*Weighted first & 2nd stage (% correctly predicted)
logit procedural comm chair ranking senate firm distcontw i.cong i.rule [pweight = percprop], robust cluster(id)
margins, dydx(comm chair ranking senate firm distcontw)

logit substantive comm chair ranking senate firm distcontw i.cong i.rule [pweight = percprop], robust cluster(id)
margins, dydx(comm chair ranking senate firm distcontw)


**Table SI-11: Conditional Effects of Staff Experience and Ideological Alignment on Type of Congressional Oversight, 2007-2017
gen dist2 = 1 if distance_ord == 2
replace dist2 = 0 if distance_ord !=2

gen dist3 = 1 if distance_ord == 3
replace dist3 = 0 if distance_ord !=3

gen dist4 = 1 if distance_ord == 4
replace dist4 = 0 if distance_ord !=4

gen dist5 = 1 if distance_ord == 5
replace dist5 = 0 if distance_ord !=5

gen interaction2 = dist2 * median_experience
gen interaction3 = dist3 * median_experience
gen interaction4 = dist4 * median_experience
gen interaction5 = dist5 * median_experience

mlogit type3 median_exper  dist2 dist3 dist4 dist5 interaction2 interaction3 interaction4 interaction5  comm chair ranking senate est_avg_office_size if firm ==0  & distance_ord !=., base(1) robust cluster(id)
*Procedural
mfx compute, predict(outcome(2)) 
*Substantive 
mfx compute, predict(outcome(3)) 

**Figure SI-3: Mulitnomial Model Including “Both” Option
mlogit type4  c.median_experience##i.distance_ord comm chair ranking senate if firm ==0 , base(2) robust cluster(id)
margins, at(median_experience = (0(1)7) distance_ord = (1)) predict(outcome(substantive)) noesample  saving(mts1, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (1)) predict(outcome(both)) noesample  saving(mtb1, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (1)) predict(outcome(procedural)) noesample  saving(mtp1, replace) 
combomarginsplot mtb1 mts1 mtp1, name(mt1, replace) labels("Both" "Substantive" "Procedural") graphregion(color(white)) title("Aligned") xtitle("") ytitle("Predicted Probability") ylab(,nogrid) xlab(none, ) legend(region(lcolor(white)))  plot1opts(msymbol(O)) plot2opts(msymbol(D))  plot3opts(msymbol(T))

margins, at(median_experience = (0(1)7) distance_ord = (2)) predict(outcome(substantive)) noesample  saving(mts2, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (2)) predict(outcome(both)) noesample  saving(mtb2, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (2)) predict(outcome(procedural)) noesample  saving(mtp2, replace) 
combomarginsplot mtb2 mts2 mtp2, name(mt2, replace) labels("Both" "Substantive" "Procedural") graphregion(color(white)) legend(off) title("Nearly Aligned") xtitle("") ytitle("") ylab(none,nogrid) xlab(none, )  plot1opts(msymbol(O)) plot2opts(msymbol(D))  plot3opts(msymbol(T))

margins, at(median_experience = (0(1)7) distance_ord = (3)) predict(outcome(substantive)) noesample  saving(mts3, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (3)) predict(outcome(both)) noesample  saving(mtb3, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (3)) predict(outcome(procedural)) noesample  saving(mtp3, replace) 
combomarginsplot mtb3 mts3 mtp3, name(mt3, replace) labels("Both" "Substantive" "Procedural") graphregion(color(white)) legend(off) title("Slight Disagreement") xtitle("") ytitle("") ylab(none,nogrid) xlab(none, )  plot1opts(msymbol(O)) plot2opts(msymbol(D))  plot3opts(msymbol(T))

margins, at(median_experience = (0(1)7) distance_ord = (4)) predict(outcome(substantive)) noesample  saving(mts4, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (4)) predict(outcome(both)) noesample  saving(mtb4, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (4)) predict(outcome(procedural)) noesample  saving(mtp4, replace) 
combomarginsplot mtb4 mts4 mtp4, name(mt4, replace) labels("Both" "Substantive" "Procedural") graphregion(color(white)) legend(off) title("Moderate Disagreement") xtitle("Staff Tenure") ytitle("Predicted Probability") ylab(,nogrid)  plot1opts(msymbol(O)) plot2opts(msymbol(D))  plot3opts(msymbol(T))

margins, at(median_experience = (0(1)7) distance_ord = (5)) predict(outcome(substantive)) noesample  saving(mts5, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (5)) predict(outcome(both)) noesample  saving(mtb5, replace) 
margins, at(median_experience = (0(1)7) distance_ord = (5)) predict(outcome(procedural)) noesample  saving(mtp5, replace) 
combomarginsplot mtb5 mts5 mtp5, name(mt5, replace) labels("Both" "Substantive" "Procedural") graphregion(color(white)) legend(off) title("High Disagreement") xtitle("Staff Tenure") ytitle("") ylab(none,nogrid)  plot1opts(msymbol(O)) plot2opts(msymbol(D)) plot3opts(msymbol(T))

grc1leg  mt1 mt2 mt3 mt4 mt5, ycommon row(2) col(3) graphregion(color(white)) name(bothcomplements, replace) 

*Table SI-12: Fixed Effects Logistic Models of Staff Experience and Ideological Alignment on Type of Con- gressional Oversight, 2007-2017
logit procedural median_exper  dist2 dist3 dist4 dist5 interaction2 interaction3 interaction4 interaction5  comm chair ranking senate est_avg_office_size i.cong i.rule if firm ==0  & distance_ord !=. , robust cluster(id)
margins, dydx(*)

logit substantive median_exper  dist2 dist3 dist4 dist5 interaction2 interaction3 interaction4 interaction5  comm chair ranking senate est_avg_office_size i.cong i.rule if firm ==0  & distance_ord !=. , robust cluster(id)
margins, dydx(*)
